var express = require("express");
var router = express.Router();
var fs = require("fs");
var path = require("path");
var { marked } = require("marked");

/* GET home page. */
router.get("/", function (req, res, next) {
  try {
    // 读取markdown文件
    const markdownPath = path.join(__dirname, "..", "部署攻略.md");
    const markdownContent = fs.readFileSync(markdownPath, "utf8");

    // 将markdown转换为HTML
    const htmlContent = marked(markdownContent);

    res.render("index", {
      title: "项目说明文档",
      markdownHtml: htmlContent,
    });
  } catch (error) {
    console.error("Error reading markdown file:", error);
    res.render("index", {
      title: "Express",
      markdownHtml: "<p>无法加载项目说明文档</p>",
    });
  }
});

module.exports = router;
